<template>
	<view class="content">
		<view class="box">
			<view class="title_box">
				<img src="../../static/image/minejijian_icon_putong@2x.png" alt="">
				<view class="title_msg">
					<view class="title_title">普通揽收</view>
					<view class="title_sub">揽收终端录入的寄件</view>
				</view>
			</view>
			<view class="data_box">
				<view class="data_title">今日揽收运单：</view>
				<view class="data_count">{{home_data.collected_count}}单</view>
			</view>
			<view class="border"></view>
			<view @click="go_order_collect" class="btn">普通揽收</view>
		</view>
		<view class="box">
			<view class="title_box">
				<img src="../../static/image/minejijian_icon_pici@2x.png" alt="">
				<view class="title_msg">
					<view class="title_title">批次寄件</view>
					<view class="title_sub">揽收PC端批量导入的寄件</view>
				</view>
			</view>
			<view class="data_box">
				<view class="data_title">今日揽收批次（运单）：</view>
				<view class="data_count">{{home_data.batch_collected_count}}批（{{home_data.batch_collected_order_count}}单）</view>
			</view>
			<view class="border"></view>
			
			<view @click="go_batch_collect" class="btn">批次揽收</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: '',
				home_data: {
					collected_count: '-',
					batch_collected_count: '-',
					batch_collected_order_count: '-',
				},
			}
		},
		onShow() {
			// 登录 获取token
			uni.getStorage({
				key: 'token',
				success: res => {
					this.token = res.data
					this.get_home_data(res.data)
				},
				fail: err => {
					uni.login({
						provider:'weixin',
						success: res => {
							if (res.code){
								// 传code
								this.$https.get(`api/mini_collection/v1/admin/certificate_login?code=${res.code}`)
								.then(res => {
									if (res.data.token) {
										this.log_state = true
										this.token = res.data.token
										uni.setStorage({
											key: 'token',
											data: res.data.token,
											success: res2 => {
												this.get_home_data(res.data.token)
											}
										})
									} else {
										uni.setStorage({
											key: 'login_data',
											data: res.data,
											success: res => {
												uni.navigateTo({
													url: '../login/login'
												})
											}
										})
									}
								})	
							}
						}
					})
				}
			})
			
		},
		methods: {
			// 获取首页数据
			get_home_data (token) {
				this.$https.get(`api/mini_collection/v1/base/home?token=${token}`)
				.then(res => {
					if (res) {
						this.home_data = res.data
					}
				}) 
			},
			// 点击跳转普通面单列表页
			go_order_collect () {
				uni.navigateTo({
					url: "../orderCollect/orderCollect"
				})
			},
			go_batch_collect () {
				uni.navigateTo({
					url: "../batchCollect/batchCollect"
				})
			}
		}
	}
</script>

<style>
	.content {
		height: 100%;
		width: 100%;
		overflow-x: hidden;
	}
	.box{
		width: calc(100% - 48rpx);
		margin-left: 24rpx;
		margin-top: 24rpx;
		background: #ffffff;
		border-radius: 12rpx;
		padding-bottom: 24rpx;
	}
	.title_box{
		display: flex;
		align-items: center;
		padding-top: 24rpx;
		margin-left: 24rpx;
		margin-bottom: 24rpx;
	}
	.title_box img{
		width: 80rpx;
		height: 80rpx;
		margin-right: 24rpx;
	}
	.title_title{
		font-size: 32rpx;
		color: #333333;
	}
	.title_sub{
		color: #999999;
		font-size: 24rpx;
	}
	.data_box{
		display: flex;
		padding-top: 24rpx;
		width: calc(100% - 48rpx);
		margin-left: 24rpx;
		align-items: center;
		justify-content: space-between;
		padding-bottom: 24rpx;
	}
	.data_title{
		font-size: 28rpx;
		color: #666666;
	}
	.data_count{
		font-size: 28rpx;
		color: #666666;
	}
	.border{
		width: calc(100% - 48rpx);
		margin-left: 24rpx;
		background-color: #eeeeee;
		height: 2rpx;
	}
	.btn{
		width: calc(100% - 48rpx);
		margin-left: 24rpx;
		text-align: center;
		background-color: #13A684;
		border-radius: 12rpx;
		height: 150rpx;
		line-height: 150rpx;
		color: #ffffff;
		font-size: 50rpx;
		margin-top: 24rpx;
	}
</style>
